package com.xingxing.Fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.xingxing.Activity.CustomCaptureActivity;
import com.xingxing.Activity.R;
import com.xingxing.Activity.databinding.FragmentHomeBinding;
import com.xingxing.Adapter.DeviceAdapter;
import com.xingxing.Bean.Device;
import com.xuexiang.xui.widget.progress.CircleProgressView;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends Fragment implements CircleProgressView.CircleProgressUpdateListener {
    private FragmentHomeBinding binding;
    /**
     * 定制化扫描界面Request Code
     */
    public static final int REQUEST_CUSTOM_SCAN = 113;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentHomeBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        binding.recyclerviewDevice.setLayoutManager(new LinearLayoutManager(getContext()));

        List<Device> list = new ArrayList<>();
        list.add(new Device("1001", "梧州学院科技楼K801", "在线"));
        list.add(new Device("1002", "梧州学院北区宿舍B7-525", "离线"));
        list.add(new Device("1003", "梧州学院北区宿舍B7-526", "离线"));

        DeviceAdapter deviceAdapter = new DeviceAdapter(getContext(), list);
        binding.recyclerviewDevice.setAdapter(deviceAdapter);

        binding.icScanner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CustomCaptureActivity.start(getActivity(), 111, R.style.XQRCodeTheme_Custom);
            }
        });

//        binding.progressViewCircleMain.setGraduatedEnabled(true);
//        binding.progressViewCircleMain.setProgressViewUpdateListener(this);
//        binding.progressViewCircleMain.startProgressAnimation();
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
//        binding.progressViewCircleMain.stopProgressAnimation();
//        binding.progressViewCircleMain.setProgressViewUpdateListener(null);
        binding = null;
    }


    @Override
    public void onCircleProgressStart(View view) {

    }

    /**
     * 进度条更新中
     *
     * @param view
     * @param progress
     */
    @Override
    public void onCircleProgressUpdate(View view, float progress) {
//        int progressInt = (int) progress;
//        if (view.getId() == R.id.progressView_circle_main) {
//
//        }
    }

    /**
     * 进度条更新结束
     *
     * @param view
     */
    @Override
    public void onCircleProgressFinished(View view) {

    }
}
